﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using WebUI.Binders;
using Entities;

namespace WebUI
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "SearchFileTypes", // Route name
                "{controller}/{action}/{selectedFileTypes}", // URL with parameters
                new { controller = MVC.Filters.Name, action = MVC.Filters.ActionNames.OpenFileTypesDialog },
                new { controller = MVC.Filters.Name }
                );

            routes.MapRoute(
                "FileDetails", // Route name
                "{controller}/{action}/{objectName}", // URL with parameters
                new { controller = MVC.Details.Name, action = MVC.Details.ActionNames.FileDetails },
                new { action = MVC.Details.ActionNames.FileDetails }
                );

            routes.MapRoute(
             "UserDetails", // Route name
             "{controller}/{action}/{UserName}", // URL with parameters
             new { controller = MVC.Details.Name, action = MVC.Details.ActionNames.UserDetails },
             new { action = MVC.Details.ActionNames.UserDetails }
             );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}", // URL with no parameters
                new { controller = MVC.Reports.Name, action = MVC.Reports.ActionNames.Overview } // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
            ModelBinders.Binders.Add(typeof(FilterOperations), new FilterModelBinder());
        }
    }
}